/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2023-04-22
 * Time:16:13
 */

/**
 * JZ16数值的整数次方
 */

public class Power {
    public static void main(String[] args) {
        System.out.println(Power(2.1,3));
    }
    public static double Power(double base, int exponent) {
        if (exponent == 0) {
            return 1;
        }
        double res = base;
        boolean flag = false;
        if (exponent < 0) {
            flag = true;
            exponent = -exponent;
        }
        exponent -= 1;
        while (exponent != 0) {
//            if ((exponent & 1) == 1) {
//                res *= base;
//            }
            base *= res;
            exponent -= 1;
        }
        return flag ? 1 / base : base;
    }
}
